<template>
	<view class="content">
		<u-navbar back-text="" title="">
			<view style="width: 100%;display: flex;justify-content: center;font-weight: bold;font-size: 34rpx;margin-left: 25rpx;">
				消息转发
			</view>
			<view slot="right">
				<view v-if="groupusers.length > 0" @click="sends" style="margin-right: 15rpx;color: #fff;background: #00aaff;padding: 10rpx 15rpx;border-radius: 8rpx;">
					转发({{groupusers.length}})
				</view>
				<view v-else style="margin-right: 15rpx;color: #fff;background: #ddf2ff;padding: 10rpx 15rpx;border-radius: 8rpx;">
					转发
				</view>
			</view>
		</u-navbar>
		<view v-if="groupusers.length > 0"
			style="width: 100%;display: flex;align-items: center;background: white;padding: 15rpx;flex-wrap: wrap;border-bottom: 1rpx solid #d9d9d955;">
			<view class="" v-for="(item,k) in groupusers">
				<u-avatar v-if="item.gid == 0" :src="$store.state.common.systemInfo.fileurl + 'avatar/' + item.fid + '.jpg'" size="80" style="margin: 10rpx;"
					mode="square"></u-avatar>
				<bgyx-group-avatar :id="item.gid" v-else />
			</view>
		</view>
		
		<view v-else
			style="width: 100%;display: flex;align-items: center;background: white;padding: 35rpx 15rpx;flex-wrap: wrap;border-bottom: 1rpx solid #d9d9d955;color: #959595;">
			选择转发聊天
		</view>

		<view style="width: 100%;display: flex;flex-direction: column;padding: 20rpx;background: white;">
			<view  @click="clickuser(item)" style="width: 100%;display: flex;align-items: flex-start;margin-bottom: 20rpx;margin-top: 10rpx;"
				v-for="(item,k) in list">
				<view>
					<u-avatar v-if="item.gid == 0" mode="square" size="90"
						:src="$store.state.common.systemInfo.fileurl + 'avatar/' + item.fid + '.jpg'"></u-avatar>
					<bgyx-group-avatar :id="item.gid" v-else />
				</view>
				<view
					style="flex: 1;display: flex;justify-content: space-between;align-items: center;padding: 0rpx 20rpx 10rpx 20rpx;height: 100rpx;border-bottom: 1rpx solid #e1e1e155;">
					<view style="display: flex;flex-direction: column;flex: 1;">
						<view
							style="font-weight: bold;font-size: 30rpx;width: 100%;display: flex;justify-content: space-between;">
							<view style="font-size: 32rpx;">
								{{item.name}}
							</view>
							<view style="font-size: 20rpx;color: #c6c6c6;font-weight: normal;">
								<image v-if="haveue(item)" src="/static/images/checked.png" style="width: 40rpx;height: 40rpx;" mode=""></image>
								<image v-else src="/static/images/check.png" style="width: 40rpx;height: 40rpx;" mode=""></image>
							</view>
						</view>
						<view style="font-size: 25rpx;color: #999;margin-top: 8rpx;width: 500rpx;" class="u-line-1">
							<bgyx-msg-display :info="item" />
						</view>
					</view>
					
				</view>
			</view>
			
		</view>


	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import {
		pub
	} from '../../common/event';
	export default {
		data() {
			return {
				scrollTop: '',
				groupusers: [],
				grids:[],
				id:''
			}
		},
		components: {

		},
		computed: {
			...mapState({
				list: (state) => {
					return state.friend.list.filter(e=>e.status != '拉黑' && e.status != '被拉黑' && e.status != '被删除')
				}
			})
		},
		onLoad({id}) {
			this.id = id
			
		},
		methods: {
			clickuser:function(e){
				if(this.grids.includes(e.id)){
					this.removeusercs(e)
				}else{
					this.changeusercs(e)
				}
			},
			changeusercs: function(e) {
				console.log(e)
				this.groupusers.push(e)
				console.log(this.groupusers)
				this.grids = this.groupusers.map(e=>e.id)
				console.log(this.grids)
			},
			removeusercs: function(e) {
				console.log(e)
				const arr = []
				for(let o of this.groupusers){
					if(o.id != e.id){
						arr.push(o)
					}
				}
				this.groupusers = arr
				this.grids = this.groupusers.map(e=>e.id)
			},
			haveue: function(e){
				return this.grids.includes(e.id)
			},
			sends: async function(){
				console.log(this.grids)
				console.log(this.groupusers)
				const targets = this.groupusers.map(e=>{
					return {
						fid:e.fid,
						uid:e.uid,
						gid:e.gid,
					}
				})
				const user = this.$store.state.user.user
				const ret = await this.$u.post(`chat/chat/shareMessage`, {id:this.id,uid:user.id,targets})
				uni.navigateBack()
			},
		}
	}
</script>


<style scoped>
	page{
		background: white;
	}
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
	}
</style>